package haemers.collections.tests 
{
	import nl.haemers.data.collections.List;
	import org.flexunit.Assert;
	/**
	 * ...
	 * @author Jonathan
	 */
	public class ListTest 
	{
		private var _list:List;
		private var _listItem:Object = new Object();
		
		/** Public methods **/
		[Before]
		public function setup() : void
		{
			_list = new List();
			_list.add("key1", {id:"1"} );
			_list.add("key2", _listItem );
		}
		
		[Test]
		public function testListProperties() : void
		{
			Assert.assertEquals(_list.size, 2);
		}
		
		[Test]
		public function testListLookupByKey() : void
		{
			Assert.assertTrue(_list.hasKey("key1"));
		}
		
		[Ignore]
		[Test]
		public function testListLookupByObject() : void
		{
			//TODO: Implement this method!
			Assert.assertTrue(_list.hasObject(_listItem));
		}
		
		[Test]
		public function testListSearch() : void
		{
			Assert.assertNotNull(_list.search("key1"));
		}
		
		[Test]
		public function testModifyList() : void
		{
			Assert.assertTrue(_list.remove("key2"));
			Assert.assertEquals(_list.size, 1);
			
			Assert.assertFalse(_list.remove("key2"));
			Assert.assertEquals(_list.size, 1);
			
			Assert.assertTrue(_list.add("key2", { id: "2" } ));			
			Assert.assertEquals(_list.size, 2);
			
			_list.overwriteAble = true;
			Assert.assertTrue(_list.add("key2", { id: "overwritten" } ));
			Assert.assertEquals(_list.size, 2);
		}
		
		[Test(description="Add a key to the list wich already excists.", expects="Error")]
		public function testAddToListException() : void
		{
			Assert.assertFalse(_list.overwriteAble);
			Assert.assertFalse(_list.add("key1", { } ));
		}
		
		[After]
		public function teardown() : void
		{
			_list.clear();
			_list = null;
		}
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
	}

}